import request from '@/utils/request'
import type { ApiResponse } from '@/types/api'

// 定义合同相关类型
interface Contract {
  id: number
  name: string
  code: string
  subject_id: number
  cate_id: number
  customer_id: number
  sign_time: string
  end_time: string
  total_amount: number
  pay_type: number
  cost_amount: number
  cost_diff: number
  check_status: number
  archive_status: number
  stop_status: number
  void_status: number
  remark: string
  create_time: string
  update_time: string
}

// 获取销售合同列表
export function getSaleContractList(params: any): Promise<ApiResponse<Contract[]>> {
  return request({
    url: '/api/contract/sale/index',
    method: 'get',
    params,
  })
}

// 获取合同详情
export function getContractDetail(id: number): Promise<ApiResponse<Contract>> {
  return request({
    url: '/api/contract/contract/detail',
    method: 'get',
    params: { id },
  })
}

// 新增合同
export function addContract(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/add',
    method: 'post',
    data,
  })
}

// 编辑合同
export function editContract(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/edit',
    method: 'post',
    data,
  })
}

// 删除合同
export function deleteContract(id: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/delete',
    method: 'post',
    data: { id },
  })
}

// 归档合同
export function archiveContract(id: number, status: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/archive',
    method: 'post',
    data: { id, status },
  })
}

// 中止合同
export function stopContract(id: number, status: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/stop',
    method: 'post',
    data: { id, status },
  })
}

// 作废合同
export function voidContract(id: number, status: number): Promise<ApiResponse<any>> {
  return request({
    url: '/api/contract/contract/void',
    method: 'post',
    data: { id, status },
  })
}

// 获取合同分类列表
export function getContractCategories(params: any): Promise<ApiResponse<any[]>> {
  return request({
    url: '/api/contract/cate/index',
    method: 'get',
    params,
  })
}
